The Line command plots a line using the current graphics color that was set
with SetColor.
Description
Line can display a line on the screen from coordinates x1,y1 to x2,y2.
The x coordinates can range from 0-319 and the y coordinates can range
from 0-199. An error is returned if the coordinates are outside these values.
Example
var x1: number;
var y1: number;
var x2: number;
var y2: number;
var n: number;
randomize;
for (n= 1 to 1000)
x1 := rand(0, 319);
y1 := rand(0, 199);
x2 := rand(0, 319);
y2 := rand(0,199);
setcolor(rand(1, 255));
line(x1, y1, x2, y2);
endl;
Declaration
Loop(control variable:number = initial value TO final value: number)
Purpose
Loop specifies certain commands to be executed repeatedly.
Description
The Loop statement causes commands to be repeatedly executed while a
progression of values is assigned to a control variable. The control
variable must be a number type and already defined. The value of the
control variable is incremented by one for each repetition. If initial
value is greater or less than final value, the contained commands isn't
executed. Commands will executed down to the Endl command. There must be
a matching Endl for every loop or and error will be returned.
Example
var n: number;
loop(n = 1 to 10)
println(n);
endl;
Declaration
Plot(x:number, y: number)
Purpose
Plots a single pixel on the screen using the current color.
Description
Plot will draw a pixel on the screen at the specified coordinate
using the color set by the last SetColor command. The x value can range
from 0-319 and the y value can range from 0-199. Any values outside these
ranges results in a run-time error.
Example
plot(50, 50);
plot(160, 100);
Declaration
Print(expression:number|string|string constant)
Purpose
Outputs data to the screen with no line feed.
Description
Print can display a number, string and string constant (text between double quotes).
Print does not move the cursor to the next line. Print will use the color set by
the last call to SetColor and will be printed at the current cursor position.
Example
var n: number;
var s: string;
n := 100;
s := "Jarrod Davis"
print("This is a test");
print(n);
print(s);
print(n => 100); {will display TRUE}
print(n = 1); {will display FALSE}
Declaration
PrintLn;
Purpose
Outputs data to screen with line feed.
Declaration
Same as Print but performs a line feed and move the cursor to the beginning
of the next line.
Declaration
Rand(min: number, max: number)
Example
See Print example.
Purpose
Returns a random number between min and max.
Description
Rand can be used to get a random number between minimum range of (0) and maximum
range of (32767). Any values outside these ranges results in a run-time error.
Example
var n: number;
randomize;
n := rand(0, 10);
println(n);
Declaration
Randomize;
Purpose
Seeds the random generator.
Description
Randomize initializes the random generator. This statement must be called be using Rand.
Declaration
SetColor(color: number);
Purpose
Set a new color value.
Description
SetColor specifies a new color value that is used by all of the graphic routines that draws to the screen. The color value can range between 0 and 255. Any values outside this range will result in a run-time error.
Example
SetColor(50);
Declaration
SetCursor(x: number, y: number);
Purpose
Sets the current cursor position.
Description
SetCursor sets the new graphics cursor position. The x coordinate can range from 0 to 319 and the y coordinate can range from 0 to 199. Any values outside the ranges will result in a run-time error.
Example
SetCursor(50, 50);
Declaration
To
Purpose
Used only in the Loop command when specifying the initial and final values.
Description
To must be used to separate the initial and final values in the Loop command.
A run-time error is returned is it is not found.
Example
var x: number;
loop(x = 1 TO 100);
...
endl;
Declaration
Var
Purpose
Declares a variable.
Description
Var is used to declare a variable. Rex++ uses two types of variables, a number
and a string. Variables have to be declared before used or a run-timer error
will result.
Example
var n: number;
var s: string;
n := 1;
s := "test";
println(n);
println(s);
Declaration
WhereX;
Purpose
Returns the current X coordinate of the graphics cursor.
Description
WhereX is a function that returns the current horizontal position of the
graphics cursor. It will return a value in the range of 0 to 319.
Example
println(wherex);
Declaration
WhereY
Purpose
Returns the current Y coordinate of the graphics cursor.
Description
WhereY is a function that returns the current vertical position of the
graphics cursor. It will return a value in the range of 0 to 199.
Example
println(wherey);
Examples
This section contains listings for a number of example programs that demonstrates
the various features of the Rex++ language. All of these programs will be installed
on your hard drive along with DOMINATION, so you don't have type them in. To load
any of them, simply note their name(s) and use the LOAD command from the IDE.
The first example shown below in Listing 1.0 illustrates the use of the random
number generator coupled with the clear screen function. The program begins by
declaring a loop variable followed by seeding the random number generator. The
program then enters the main loop which iteratively clears the screen with a new
random color each cycle.
Listing 1.0 - CLS.RPP
{ This program demonstrates the cls command }
var x: number; { declare x as a number }
randomize; { initialize random number generator }
loop(x=1 to 50) { setup to loop from 1 to 50 }
cls(rand(0, 255)); { clear the screen with a random color }
delay(50); { pause program execution for 50 milliseconds }
endl { end the loop }
The next example program shown below in Listing 2.0 illustrates how to use the
cursor setting and querying functions. The program sets the position of
the cursor and then retrieves it with the "where" functions. This is a good
example of how to track your text output for formatting.
Listing 2.0 - CURSOR.RPP
{ This program demonstrates the setcursor command }
var x: number; { declare x as a number }
var y: number; { declare y as a number }
setcursor(50, 80); { set graphics cursor to position 50,80 }
println(""); { print a blank line }
print("X = ",wherex); { print value of current horizontal position }
print("Y = ",wherey); { print value of current vertical position }
All computer languages allow complex expressions to be evaluated, however,
Rex++ goes a little farther in some areas such as string processing. Listing 3.0
below shows both numeric and string data types benig defined and output. Notice the
use of the addition operator to concatenate strings together, this is a very
powerful language construct.
Listing 3.0 - EXPR.RPP
{ This program demonstrates expressions and strings }
var s: string; { declare x as a string }
var n: number; { declare n as a number }
n := 100 + 100; { assign n a number value }
s := "This is a test" + " this is another test "; { assign s a string value }
println(s); { print value of s }
println(n); { print value of n }
println("I am the " + "Man!"); { print a string expression }
println( ((4*5) / 2) + (100/2)); { print a number expression }
The next example below, Listing 4.0 is our first program that does something a bit
graphical. The program begins by declaring a number of working variables, the
program then enters into a main loop and repeatedly computes a set of random
numbers. These numbers are used as parameters to the color and line drawing
functions. The result, a collection of random lines drawn on the screen in
random colors.
Listing 4.0 - LINE.RPP
{ This program demonstrates the line command}
randomize; { setup the random number generator }
line(0,0,319,199); { draw a diagonal line from 0,0 to 319,199 }
var n: number; { declare n as a number }
var x1: number; { declare x1 as a number }
var y1: number; { declare y1 as a number }
var x2: number; { declare x2 as a number }
var y2: number; { declare y2 as a number }
loop(n=1 to 1000) { set n to loop from 1 to 1000 }
x1 := rand(0, 319); { assign x1 a random number from 0 to 319 }
y1 := rand(0, 199); { assign y1 a random number from 0 to 199 }
x2 := rand(0, 319); { assign x2 a random number from 0 to 319 }
y2 := rand(0, 199); { assign y2 a random number from 0 to 199 }
setcolor(rand(1, 255); { set graphics color a random color from 1 to 255 }
line(x1, y1, x2, y2); { draw line }
endl; { end loop }
Listing 5.0 below is similar to Listing 4.0 except that instead drawing random line
segments, random pixels are drawn. However, don't be fooled by the example's
simplicity since there is a more important language construct to be learned here.
Notice that instead of using local variables to hold random data values, the
random pixel postions are computed as parameters to the plot function. Hence, you
may use this technique freely to save a local variable(s).
Listing 5.0 - PLOT.RPP
{ This program demonstrates the plot command }
var x: number; {declare x as a number}
randomize; {seed random number generator}
loop(x=1 to 10000) { set x to loop from 1 to 1000 }
setcolor(rand(1, 255)); { set graphics color a random number from 1 to 255 }
plot(rand(0, maxx), rand(0, maxy)); { plot pixel at random x,y position }
endl; { end loop }
println("I am the man!"); { print a string expression }
No language would be complete without the ability to create text output. Rex++ has
two functions to accomplish this task: print() and println(). Listing 6.0 below
shows an example use of both of these functions, notice that the functions can
take either numeric or string data.
Listing 6.0 - PRINT.RPP
{ This program demonstrates the print/println commands}
var x:number; { declare x as a number }
var y:string; { declare y as a string }
loop(x=1 to 10) { setup x to loop from 1 to 10 }
println("number: ", x); { print value of x }
endl; { end loop }
print("this is a test"); { print string constant with no line feed}
println(" this is on the same line."); { print string constant with line feed }
println("but this is not."); { print string constant with line feed }
Listing 7.0 is a formal example of using the random functions, not too exciting!
Listing 7.0 - RAND.RPP
{ This program demonstrates the randomize/rand commands}
randomize; { setup random number generator }
var n: number; { declare n as a number }
loop(n=1 to 20) { set n to loop from 1 to 20 }
println(rand(1, 1000)); { print a random number between 1 and a 1000 }
endl; { end loop }
Listing 8.0 below illustrates the use of the real-time keyboard I/O functions
which allow you to not only detect if a key has been pressed, but if multiple
keys have been pressed. This particular example shows how to track the arrow keys.
Listing 8.0 - KEYTEST.RPP
{ This program demonstrates the kbcode function and the goto command }
println("Press the arrow keys, <ESC> to quit..."); { tell what to do }